﻿using System;
using System.Collections.Generic;
using System.Text;

namespace DataStructureSample.StackDs
{
    public class SeqStack<T>
        : IStackDs<T>
    {
        private T[] _data;
        private int _top;
        public SeqStack(int size)
        {
            _data=new T[size];
            _top = -1;
        }
        public SeqStack()
            :this(10)
        {}
        public int Count => _top+1;

        public void Clear()
        {
            _top = -1;
        }

        public int GetLength()
        {
            return Count;
        }

        public bool IsEmpty()
        {
            return Count == 0;
        }

        public T Peek()
        {
            var temp = _data[_top - 1];
            return temp;
        }

        public T Pop()
        {
            var temp = _data[_top - 1];
            _top--;
            return temp;
        }

        public void Push(T item)
        {
            _top++;
            _data[_top] = item;
        }
    }
}
